import request from "@/common/http";
import member_log from './mock/member_log.json'
import memberLevel from './mock/member_level.json'
import memberList from './mock/memberList.json'
import memberAddress from './mock/member_address.json'
import {Member, MemberAddress, MemberLevel, MemberLoginLog} from "@/common/interfaces/member";

export async function queryMemberList(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(memberList)
  }
  return request('/api/member/member/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeMember(params: { ids: number[] }) {
  return request('/api/member/member/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function addMember(params: Member) {
  return request('/api/member/member/add', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateMember(params: Member) {
  return request('/api/member/member/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function queryAddress(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(memberAddress)
  }
  return request('/api/member/address/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeAddress(params: { ids: number[] }) {
  return request('/api/member/address/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function addAddress(params: MemberAddress) {
  return request('/api/member/address/add', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateAddress(params: MemberAddress) {
  return request('/api/member/address/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}


export async function queryLevel(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(memberLevel)
  }
  return request('/api/member/level/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}


export async function removeLevel(params: { ids: number[] }) {
  return request('/api/member/level/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function addLevel(params: MemberLevel) {
  return request('/api/member/level/add', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function updateLevel(params: MemberLevel) {
  return request('/api/member/level/update', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}


export async function queryLoginLog(params?: any, useMock?: boolean) {
  if (useMock) {
    return Promise.resolve(member_log)
  }
  return request('/api/member/loginlog/list', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

export async function removeLoginLog(params: { ids: number[] }) {
  return request('/api/member/loginlog/delete', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
